<?php

$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
set_include_path(get_include_path().PATH_SEPARATOR.$baseDir.PATH_SEPARATOR.$baseDir.'/incubator');

include '../../testingfunctions.php';
include 'Pone/Pone_Exception.php';
include 'Pone/Database/Pone_Database_ConnectionFactory.php';
include_once './dbconfig.php'; // $config is defined here
include_once './test_setup.php'; // refreshTestData() is defined here

try
{
    refreshTestData($config);
    // /home/web/windows.php.net/docroot/downloads/snaps/
    $conn = Pone_Database_ConnectionFactory::getConnection($config);
    $stmt = $conn->createStatement();

    $insertData  = array(
      'username'   => 'pcdinh8',
      'id'         => 8,
      'seq_number' => 8,
    );

    $affectedRowCount = $stmt->insert('test2', $insertData);
    assertTrue($affectedRowCount === 1, 'Expected: One row is affected. ');
    echo '<br />';
    $justInsertUsername = $stmt->fetchOne('SELECT username FROM test2 WHERE id = 8');
    assertTrue($justInsertUsername === 'pcdinh8', 'Expected: The username which has just been just inserted is pcdinh8');
    $stmt->execute('DELETE FROM test2 WHERE id = 8');

    // Free resources
    $stmt->close();
}
catch (Pone_Exception_DatabaseAccess $ex)
{
    echo implode('. ', $ex->getTraceMessages());
    echo '<br />';
    echo $ex->getNativeMessage();
}
catch (Exception $ex)
{
    echo $ex->getMessage();
}

$conn->close();
?>